package com.alesj.newsfeed.bool.impl;

import java.util.Set;

import com.alesj.newsfeed.bool.Condition;
import com.alesj.newsfeed.bool.Token;
import com.alesj.newsfeed.bool.ConditionCreator;

/**
 * @author <a href="mailto:ales.justin@gmail.com">Ales Justin</a>
 */
public class Not<C> implements Token<Condition<C>> {

    private ConditionCreator<C> creator;
    private Condition<C> condition;

    public Not(ConditionCreator<C> creator, Condition<C> condition) {
        this.creator = creator;
        this.condition = condition;
    }

    public Condition<C> value() {
        return new LazyCondition();
    }

    private class LazyCondition implements Condition<C> {
        public Set<C> execute() {
            Set<C> all = creator.all();
            Set<C> not = condition.execute();
            all.removeAll(not);
            return all;
        }
    }
}
